﻿

using Maticsoft.BLL;
using Maticsoft.Model;
using System;
using System.Text;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Wuqi.Webdiyer;

public partial class WebPage_ShangHu : SystemBBasePage
{

    private Maticsoft.BLL.Category cateGory = new Maticsoft.BLL.Category();
    private Maticsoft.Model.Category categoryModel = new Maticsoft.Model.Category();

    private Maticsoft.BLL.Partner patn = new Maticsoft.BLL.Partner();
    private bool result;
    private bool result2;

    private string sql = "1=1 ";
    private int text = Convert.ToInt32(PageIndex.pageIndex);
    private string where = "";

    protected void AspNetPager1_PageChanging(object src, PageChangingEventArgs e)
    {
        this.result2 = true;
        this.page(this.sql, this.text);
        this.sql = string.Concat(new object[] { this.sql, " and  Id not in(select top ", (e.NewPageIndex - 1) * this.text, " Id from Partner where ", this.sql, " order by Id desc) " });
        this.pdbshow(this.text, 10);
    }

    private void citySum()
    {
        StringBuilder builder = new StringBuilder();
        builder.Append("<select name='city_id' class='h-input'>");
        builder.Append("<option value='0' selected>全部城市</option>");
        foreach (Maticsoft.Model.Category category in this.cateGory.GetModelList("Zone='city'"))
        {
            builder.Append(string.Concat(new object[] { "<option value='", category.Id, "' >", category.Name, "</option>" }));
        }
        builder.Append("</select>");
        this.Literal3.Text = builder.ToString();
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        this.HeaderControl1.Select = "shanghu";
        if (!this.Page.IsPostBack)
        {
            if (this.Session["sql"] != null)
            {
                this.Session.Remove("sql");
            }
            this.xiuSum();
            this.citySum();
            this.typeSum();
            if (base.Request.QueryString["remove"] != null)
            {
                this.patn.Delete(int.Parse(base.Request.QueryString["remove"].ToString()));
                base.SetSuccess("删除成功");
            }
            if ((base.Request["action"] != null) && (base.Request["action"].ToString() != ""))
            {
                int maxHead = this.patn.GetMaxHead();
                this.patn.UpdateHead(int.Parse(base.Request["action"].ToString()), maxHead);
                base.SetSuccess("置顶成功");
            }
        }
        this.pdbshow(this.text, 10);
    }

    private void page(string where, int count)
    {
        this.AspNetPager1.AlwaysShow = true;
        this.AspNetPager1.PageSize = count;
        this.AspNetPager1.RecordCount = this.patn.GetModelList(where).Count;
        this.AspNetPager1.DataBind();
    }

    private void pdbshow(int pageSum, int index)
    {
        if ((base.Request.Form["username"] != null) && (base.Request.Form["username"].ToString() != ""))
        {
            this.sql = this.sql + " and Title like '" + base.Request.Form["username"].ToString() + "%' ";
            this.Session.Add("sql", this.sql);
            this.result = true;
        }
        if ((base.Request.Form["open"] != null) && (base.Request.Form["open"].ToString() != ""))
        {
            this.sql = this.sql + " and [Open]='" + base.Request.Form["open"].ToString() + "' ";
            this.Session.Add("sql", this.sql);
            this.result = true;
        }
        if (((base.Request.Form["city_id"] != null) && (base.Request.Form["city_id"].ToString() != "")) && (base.Request.Form["city_id"].ToString() != "0"))
        {
            this.sql = this.sql + " and City_id=" + base.Request.Form["city_id"].ToString() + " ";
            this.Session.Add("sql", this.sql);
            this.result = true;
        }
        if ((base.Request.Form["part"] != null) && (base.Request.Form["part"].ToString() != ""))
        {
            this.sql = this.sql + " and Group_id=" + base.Request.Form["part"].ToString() + " ";
            this.Session.Add("sql", this.sql);
            this.result = true;
        }
        if (this.result)
        {
            this.sql = this.Session["sql"].ToString();
        }
        this.where = this.sql + " order by Id desc";
        StringBuilder builder = new StringBuilder();
        builder.Append("<tr >");
        builder.Append("<th width='40'>ID</th>");
        builder.Append("<th width='320'>名称</th>");
        builder.Append("<th width='60'>分类</th>");
        builder.Append("<th width='120'>联系人</th>");
        builder.Append("<th width='130'>电话号码</th>");
        builder.Append("<th width='60'>商户秀</th>");
        builder.Append("<th width='120'>操作</th>");
        builder.Append("</tr>");
        this.Literal5.Text = builder.ToString();
        StringBuilder builder2 = new StringBuilder();
        int num = 0;
        foreach (Maticsoft.Model.Partner partner in this.patn.GetList(pageSum, index, this.where))
        {
            if ((num % 2) != 0)
            {
                builder2.Append("<tr>");
            }
            else
            {
                builder2.Append("<tr class='alt'>");
            }
            num++;
            builder2.Append("<td>" + partner.Id.ToString() + "</td>");
            builder2.Append("<td style='text-align:left;'>");
            builder2.Append("<a class='deal-title' href='ShangHu_Bianji.aspx?id=" + partner.Id.ToString() + "'>" + partner.Title.ToString() + "</a>");
            builder2.Append("</td>");
            builder2.Append("<td nowrap>");
            this.categoryModel = this.cateGory.GetModel(partner.Group_id);
            if (this.categoryModel != null)
            {
                builder2.Append(this.categoryModel.Name);
            }
            builder2.Append("<br/>");
            this.categoryModel = this.cateGory.GetModel(partner.City_id);
            if (this.categoryModel != null)
            {
                builder2.Append(this.categoryModel.Name);
            }
            else
            {
                builder2.Append("全部城市");
            }
            builder2.Append("</td>");
            builder2.Append("<td nowrap>" + partner.Contact.ToString() + "</td>");
            builder2.Append("<td nowrap>" + partner.Phone.ToString() + "<br/>" + partner.Mobile.ToString() + "</td>");
            builder2.Append("<td nowrap>" + partner.Open.ToString() + "</td>");
            builder2.Append("<td class='op' nowrap>");
            builder2.Append("<a href='ShangHu_Bianji.aspx?id=" + partner.Id.ToString() + "'>编辑\t</a>｜");
            builder2.Append("<a href='ShangHu.aspx?action=" + partner.Id.ToString() + "' >置顶 </a>｜");
            builder2.Append("<a href='ShangHu.aspx?remove=" + partner.Id.ToString() + "'>删除</a>");
            builder2.Append("</td>");
            builder2.Append("</tr>");
        }
        this.Literal1.Text = builder2.ToString();
        if (!this.result2)
        {
            this.page(this.where, this.text);
        }
    }

    private void typeSum()
    {
        StringBuilder builder = new StringBuilder();
        builder.Append("<select name='part' class='h-input'>");
        builder.Append("<option value='' selected>全部分类</option>");
        foreach (Maticsoft.Model.Category category in this.cateGory.GetModelList("Zone='partner'"))
        {
            builder.Append(string.Concat(new object[] { "<option value='", category.Id, "' >", category.Name, "</option>" }));
        }
        builder.Append("</select>");
        this.Literal4.Text = builder.ToString();
    }

    private void xiuSum()
    {
        StringBuilder builder = new StringBuilder();
        builder.Append("<select name='open' class='h-input'>");
        builder.Append("<option value='' selected>全部秀</option>");
        builder.Append("<option value='Y' >开放展示</option>");
        builder.Append("<option value='N' >关闭展示</option>");
        builder.Append("</select>");
        this.Literal2.Text = builder.ToString();
    }
}


